import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:example/base/styles.dart';
import 'package:example/base/web_page_transitions.dart';

import '../config/color_config.dart';

ThemeData getTheme({bool isDarkMode = false}) {
  return ThemeData(
    colorScheme: ColorScheme.light(
        primary:  isDarkMode ? ColorConfig.dark_app_main : ColorConfig.app_main,
        secondary:
            isDarkMode ? ColorConfig.dark_app_main : ColorConfig.app_main,
      error: isDarkMode ? ColorConfig.dark_red : ColorConfig.red,
    ),
    // brightness: isDarkMode ? Brightness.dark : Brightness.light,
    primaryColor: isDarkMode ? ColorConfig.dark_app_main : ColorConfig.app_main,

    // Tab指示器颜色
    indicatorColor:
        isDarkMode ? ColorConfig.dark_app_main : ColorConfig.app_main,
    // 页面背景色
    scaffoldBackgroundColor:
        isDarkMode ? ColorConfig.dark_bg_color : ColorConfig.page,
    // 主要用于Material背景色
    canvasColor: isDarkMode ? ColorConfig.dark_material_bg : ColorConfig.page,
    // 文字选择色（输入框选择文字等）
    // textSelectionColor: ColorConfig.app_main.withAlpha(70),
    // textSelectionHandleColor: ColorConfig.app_main,
    // 稳定版：1.23 变更(https://flutter.dev/docs/release/breaking-changes/text-selection-theme)
    textSelectionTheme: TextSelectionThemeData(
      selectionColor: ColorConfig.app_main.withAlpha(70),
      selectionHandleColor: ColorConfig.app_main,
      cursorColor: ColorConfig.app_main,
    ),
    textTheme: TextTheme(
      // TextField输入文字颜色
      titleMedium: isDarkMode ? TextStyles.textDark : TextStyles.text,
      // Text文字样式
      bodyMedium: isDarkMode ? TextStyles.textDark : TextStyles.text,
      titleSmall: isDarkMode ? TextStyles.textDarkGray12 : TextStyles.textGray12,
    ),
    inputDecorationTheme: InputDecorationTheme(
      hintStyle: isDarkMode ? TextStyles.textHint14 : TextStyles.textDarkGray14,
    ),
    appBarTheme: AppBarTheme(
      elevation: 0.0,
      color: isDarkMode ? ColorConfig.dark_bg_color : Colors.white,
      systemOverlayStyle: SystemUiOverlayStyle(
        statusBarBrightness: isDarkMode ? Brightness.dark : Brightness.light,
        statusBarIconBrightness: isDarkMode ? Brightness.dark : Brightness.light,
      ),
    ),
    dividerTheme: DividerThemeData(
        color: isDarkMode ? ColorConfig.dark_line : ColorConfig.line,
        space: 0.6,
        thickness: 0.6),
    cupertinoOverrideTheme: CupertinoThemeData(
      brightness: isDarkMode ? Brightness.dark : Brightness.light,
    ),
    pageTransitionsTheme: NoTransitionsOnWeb(),
    // https://github.com/flutter/flutter/issues/77142
    visualDensity: VisualDensity.standard,
  );
}
